<?php

/**
 * This is the model class for table "item".
 *
 * The followings are the available columns in table 'item':
 * @property integer $item_id
 * @property integer $producto_id
 * @property integer $tipo_categoria_id
 * @property string $nombre
 * @property string $descripcion
 * @property string $img_url1
 * @property string $img_url2
 * @property string $img_url3
 * @property integer $borrado
 * @property string $fechacreacion
 * @property integer $usuario_id
 *
 * The followings are the available model relations:
 * @property TipoCategoria $tipoCategoria
 * @property Producto $producto
 * @property Usuario $usuario
 */
class Item extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'item';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('usuario_id', 'required'),
			array('producto_id, tipo_categoria_id, borrado, usuario_id', 'numerical', 'integerOnly'=>true),
			array('nombre', 'length', 'max'=>40),
			array('img_url1, img_url2, img_url3', 'length', 'max'=>2000),
			array('descripcion', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('item_id, producto_id, tipo_categoria_id, nombre, descripcion, img_url1, img_url2, img_url3, borrado, fechacreacion, usuario_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tipoCategoria' => array(self::BELONGS_TO, 'TipoCategoria', 'tipo_categoria_id'),
			'producto' => array(self::BELONGS_TO, 'Producto', 'producto_id'),
			'usuario' => array(self::BELONGS_TO, 'Usuario', 'usuario_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'item_id' => 'Item',
			'producto_id' => 'Producto',
			'tipo_categoria_id' => 'Tipo Categoria',
			'nombre' => 'Nombre',
			'descripcion' => 'Descripcion',
			'img_url1' => 'Img Url1',
			'img_url2' => 'Img Url2',
			'img_url3' => 'Img Url3',
			'borrado' => 'Borrado',
			'fechacreacion' => 'Fechacreacion',
			'usuario_id' => 'Usuario',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('item_id',$this->item_id);
		$criteria->compare('producto_id',$this->producto_id);
		$criteria->compare('tipo_categoria_id',$this->tipo_categoria_id);
		$criteria->compare('nombre',$this->nombre,true);
		$criteria->compare('descripcion',$this->descripcion,true);
		$criteria->compare('img_url1',$this->img_url1,true);
		$criteria->compare('img_url2',$this->img_url2,true);
		$criteria->compare('img_url3',$this->img_url3,true);
		$criteria->compare('borrado',$this->borrado);
		$criteria->compare('fechacreacion',$this->fechacreacion,true);
		$criteria->compare('usuario_id',$this->usuario_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Item the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
